package com.ophiux.cs.application.consultBase.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.consultBase.dto.FocusRequest;
import com.ophiux.cs.application.consultBase.dto.FocusResponse;
import com.ophiux.cs.application.consultBase.service.IFocusAppService;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.consultBase.model.entity.Focus;
import com.ophiux.cs.infrastructure.repositories.user.FocusRepository;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class FocusAppService implements IFocusAppService{
	@Autowired
	FocusRepository focusRepository;
	
	@Override
	public Result<FocusResponse> Focus(FocusRequest dto) {
//		FocusResponse resp = new FocusResponse();
		try {
			if(!dto.isParamValid()) {
				return Result.fail(ResultEnum.requestParamFail);
			}
			
			boolean isfocus= FocusRequest.isFocus(dto.getIS_FOCUS());
			
			Focus focus = new Focus(isfocus,dto.getUSER_ID(),dto.getTARGET_ID(),dto.getTARGET_TYPE());
			
			focusRepository.save(focus);
		} catch (Exception e) {
			log.info("程序异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
		return Result.success();
	}
}
